home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / ALPHA.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  6KB  |  166 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 452 of 460
  3. From : Justin Marquez                      1:106/100.1          20 May 93  20:41
  4. To   : Steven Morales
  5. Subj : Port[] - ?
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  SM> I've see it used for keypress info and stuff...  How do I use PORT[] in
  8.  SM> general.  PORT[80] is used for when a key is pressed.  Whatelse can I do
  9.  SM> with it?  Please help me - thanks - I also need help with TSRs too...
  10.  
  11.   It can also be used to access non-standard added-in cards.  For example, ALPHA
  12. PRODUCTS makes a whole family of data-gathering devices that attach to PC's via
  13. an "Alpha Bus" card.  (They make bus cards for many different little computers -
  14. same end device cards, all adapted to different PC's via a BUS card in or
  15. attached to the PC.)  I have one of them that I have tinkered with some, the
  16. AD-142 for 8-bit analog-to-digital conversion. Here's some sample code.  Only
  17. the part for the AD-142 has been tested. The other stuff compiles OK, but I
  18. don't have the other cards (yet) to play with.}
  19.  
  20. UNIT ALPHA;
  21. { Contains the routines to access the APLHA Products line of
  22.   A-BUS Data Collection and control system I/O cards }
  23.  
  24. INTERFACE
  25. USES DOS,CRT,Printer;
  26. TYPE  AD142 = record
  27.               { All 8 channels numbers + a time & date stamp when read }
  28.                 Channel : Array [0..7] of BYTE;
  29.               end;
  30.       LI157 = record
  31.                 Read_Value : byte;
  32.                 Channel    : Array [0..7] of Boolean; { TRUE = SET or 1 }
  33.               end;
  34. CONST
  35.      Adapter_Address = 512;  { PC adapter installed at this Port
  36.                                Remember to ADD the CARD ADDRESS, too }
  37.      Card_Address    = 0;    { These two are factory defaults }
  38. VAR
  39.    Data_Point : AD142;
  40.  
  41. { copy just the HEADERS for all the procs and functions called by this
  42.   unit into this space }
  43.  
  44. FUNCTION Make_A_Stamp : LongInt;  { time/date stamp for data logging }
  45. FUNCTION POWER2 (n:Integer): Integer;
  46. PROCEDURE Read_LI_157 (Card_Number:Integer; VAR Reading : LI157);
  47. PROCEDURE DA_147_Output (Card_Number,Channel_Number,Out_Value: Integer);
  48. Function Read_A_Channel_FA154( Card_Number,Channel_Number : integer): Integer;
  49. PROCEDURE Read_AD142 ( Card_Number : Integer; VAR Reading: AD142);
  50. PROCEDURE Show_Raw_Readings(Reading: AD142); { Numbers as read in at the port }
  51.  
  52. IMPLEMENTATION
  53. { the actual procedures and functions go in here }
  54. FUNCTION Make_A_Stamp : LongInt;  { time/date stamp for data logging }
  55. Var
  56.    Date_Time  : DateTime;    { record for PackTime to munge on }
  57.    Day_Of_Week,
  58.    Sec100s    : word;        { dummies for GetDate and GetTime }
  59.    Packed_Date_And_Time : LongInt;
  60. Begin
  61.   Packed_Date_And_Time := 0;         { always init the value to SOMETHING... }
  62.   FillChar(Date_Time,SizeOf(Date_Time),#0);
  63.   WITH Date_Time DO
  64.   begin
  65.     GetDate(Year,Month,Day,Day_Of_Week);
  66.     GetTime(Hour,Min,Sec,Sec100s);
  67.     PackTime(Date_Time,Packed_Date_And_Time);
  68.     Make_A_Stamp := Packed_Date_And_Time
  69.   end
  70. End; { of Make_A_Stamp }
  71.  
  72. FUNCTION POWER2 (n:Integer): Integer;
  73. Var i : integer;
  74. Begin
  75.    i := 1;
  76.    While n > 0 DO
  77.    begin
  78.       i := i*2;
  79.       dec(n);
  80.    end;
  81. POWER2 := i
  82. End;
  83.  
  84. PROCEDURE Read_LI_157 (Card_Number:Integer; VAR Reading : LI157);
  85. Var i,Port_At : Integer;
  86. Begin
  87.   FillChar(Reading,SizeOf(Reading),#0);
  88.             { usually 512       0 to 64  }
  89.   Port_At := Adapter_Address + Card_Number;
  90.   With Reading DO
  91.   begin
  92.     Read_Value := PORT[Port_At];
  93.     For i := 0 to 7 DO
  94.       If ( ((Read_Value AND Power2(i)) = 1) ) Then Channel[i] := TRUE;
  95.   end
  96. End;
  97. PROCEDURE DA_147_Output (Card_Number,Channel_Number,Out_Value: Integer);
  98. { Compiles, but is Untested !! }
  99. Var Port_At: integer;
  100. Begin
  101.             { usually 512       0 to 64           0 to 3  }
  102.   Port_At := Adapter_Address + Card_Number + Channel_Number;
  103.   PORT[Port_At] := Out_Value;
  104.   delay(1);
  105. End; { of DA-147 Output routine }
  106.  
  107. Function Read_A_Channel_FA154( Card_Number,Channel_Number : integer): Integer;
  108. { Compiles OK but is UNTESTED with a real FA-154 card! }
  109. { This is for an ALPHA Products 12-bit Fast A/D Card, FA-154
  110.   The values returned from it range from 0 - 4095
  111.   Conversion time is 10 microseconds.(0.000010 second) }
  112. Var n, Hi, Lo, P0, P1  : Integer;
  113. Begin
  114.   P0 := Adapter_Address + Card_Number;       { Compute Card Base Port Address}
  115.   P1 := P0 +1;                               { Second Port for Hi value }
  116.   n := 0;                                { Initialize - looks good to do it  }
  117.     Port[P0] := Channel_Number;          { Tell the card which channel       }
  118.     n  := Port[P0];                      { Dummy Reading to start conversion }
  119.     Delay(1);                            { 0.001 sec. wait, may not need     }
  120.     Hi := Port[P1];                      { Read High address first           }
  121.     Lo := Port[P0];                      { Read Low Address   next           }
  122.   n := (Hi*256)+Lo;                      { Value will be between 0 and 4095  }
  123. Read_A_Channel_FA154 := n;
  124. End; { of read a channel on the FA154 }
  125.  
  126.  
  127. FUNCTION Read_A_Channel_AD142 (Card_Number,Channel_Number :integer):byte;
  128. { Tested }
  129. { This is for an 8-bit A/D Card, readings are 0 - 255, 160 microsecond
  130.   conversion time.  ALPHA Products AD142 }
  131. Var
  132.   n,
  133.   Port_At : integer;
  134. Begin
  135.   n := 0;
  136.   Port_At := Adapter_Address + Card_Number; { Compute Port Address}
  137.   Port[Port_At] := Channel_Number;          { Tell the card which channel }
  138.     delay(5);                               { wait 5 ms for conversion }
  139.   n := Port[Port_At];                       { Read data in }
  140. Read_A_Channel_AD142 := n;
  141. End; { of read one channel }
  142.  
  143. PROCEDURE Read_AD142 ( Card_Number : Integer; VAR Reading: AD142);
  144. {Tested}
  145. Var  Channel_Number, n, Port_At    : Integer;
  146. Begin
  147.   Port_At := Adapter_Address + Card_Number;{ Compute Port Address}
  148.   FillChar(Reading,SizeOf(Reading),#0);    { Clear the record first }
  149.   WITH Reading DO
  150.   begin
  151.     for Channel_Number := 0 to 7 DO
  152.         Channel[Channel_Number] := 
  153. Read_A_Channel_AD142(Card_Number,Channel_Number);
  154.   end  { of WITH... }
  155. End; { of Read_AD142 }
  156.  
  157. PROCEDURE Show_Raw_Readings(Reading: AD142); { Numbers as read in at the port }
  158. { tested }
  159. Var n : integer;
  160. Begin
  161.   For n := 0 to 7 DO
  162.     Write(Reading.Channel[n]:6);
  163. End; { of Show_Raw_Readings }
  164.  
  165.  
  166. END.